var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../utils/dateTimePicker"), e = getApp();

Page({
    data: {
        showcomment: !1,
        showInfo: !1,
        addNum: 1,
        showAddress: !1,
        info: {},
        tel: "",
        addBtn_status: !1,
        commentlist: [],
        comment_input: "",
        showWechatshar: !1,
        showShare: !1,
        options: [ {
            name: "微信分享",
            icon: "wechat",
            openType: "share"
        }, {
            name: "分享海报",
            icon: "poster"
        } ],
        showposter: !1,
        poster_url: "",
        activityInfo: {},
        addressData: [],
        isLoadMore: !1,
        page: 1,
        total_page: 0,
        percent: 0,
        btn_text: "",
        goodsPopupShow: !1,
        hand_goods_obj: {},
        activeid: 0
    },
    onLoad: function(t) {
        if (t.id && this.setData({
            activeid: t.id
        }), t.scene) {
            var a = decodeURIComponent(t.scene);
            if (console.log(a), a) {
                var e = [];
                e = a.split(","), console.log(e);
                for (var i = 0; i < e.length; i++) {
                    var o;
                    o = e[i].split("="), console.log(o), "id" == o[0] && this.setData({
                        activeid: o[1]
                    });
                }
            }
        }
        this.getData();
    },
    getData: function() {
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        var i = this, o = e.getNetAddresss("plugin.luck-draw.frontend.index.detail");
        e._postNetWork({
            url: o,
            data: {
                activity_id: i.data.activeid
            },
            success: function(e) {
                wx.hideLoading();
                var o = e.data;
                if (1 == o.result) {
                    var n = parseInt(100 * Number((o.data.max_num - o.data.activity_num) / o.data.max_num)), s = "";
                    a.setData({
                        addBtn_status: !1
                    });
                    var d = new Date().getTime();
                    1e3 * o.data.start_time > d ? s = "活动未开始" : 3 == o.data.activity_state ? s = "活动已结束" : o.data.member_num <= 0 ? s = "您已参与" : 2 == o.data.type_id ? (s = "￥".concat(o.data.money, "抽奖"), 
                    a.setData({
                        addBtn_status: !0
                    })) : 1 == o.data.type_id && (s = "免费", a.setData({
                        addBtn_status: !0
                    })), i.setData({
                        info: o.data,
                        percent: n,
                        btn_text: s
                    });
                    var c = o.data.explain.replace(/<img/g, '<img style="width:100%;display: block;"');
                    i.setData(t({}, "info.explain", c));
                } else wx.showToast({
                    title: o.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), console.log(t.msg);
            }
        });
    },
    getComment: function() {
        var t = this, i = e.getNetAddresss("plugin.luck-draw.frontend.index.getComment");
        e._postNetWork({
            url: i,
            data: {
                activity_id: t.data.activeid
            },
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    t.setData({
                        isLoadMore: !0,
                        total_page: i.data.last_page,
                        showcomment: !0
                    });
                    var o = i.data.data;
                    o.forEach(function(t) {
                        var e = new Date(t.created_at.replace(/-/g, "/")).getTime();
                        t.created_at = (0, a.timeHandle)(e);
                    }), t.setData({
                        commentlist: o
                    });
                } else wx.showToast({
                    title: i.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    closeComment: function() {
        this.setData({
            showcomment: !1
        });
    },
    getMoreData: function() {
        var t = this;
        if (t.data.isLoadMore && (this.setData({
            isLoadMore: !0
        }), !(this.data.page >= this.data.total_page))) {
            var a = {
                activity_id: t.data.activeid
            };
            this.setData({
                page: this.data.page + 1
            }), a.page = this.data.page;
            var i = e.getNetAddresss("plugin.luck-draw.frontend.index.getComment");
            e._postNetWork({
                url: i,
                data: a,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data.data, o = t.data.commentlist.concat(i);
                        t.setData({
                            commentlist: o,
                            isLoadMore: !0
                        });
                    } else {
                        var n = t.data.page;
                        t.setData({
                            isLoadMore: !1,
                            page: n - 1
                        }), wx.showToast({
                            title: e.msg,
                            duration: 1e3,
                            icon: "none"
                        });
                    }
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    getCollection: function() {
        var a = this, i = this, o = e.getNetAddresss("plugin.luck-draw.frontend.index.collection");
        e._postNetWork({
            url: o,
            data: {
                activity_id: i.data.activeid,
                state: i.data.info.is_collection ? 0 : 1
            },
            success: function(e) {
                var o, n = e.data;
                (wx.showToast({
                    title: n.msg,
                    duration: 1e3,
                    icon: "none"
                }), 1 == n.result) && i.setData((t(o = {}, "info.collection_num", 1 == a.data.info.is_collection ? a.data.info.collection_num - 1 : a.data.info.collection_num + 1), 
                t(o, "info.is_collection", !a.data.info.is_collection), o));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    addActivity: function() {
        if (this.data.addBtn_status) {
            var t = this, a = e.getNetAddresss("plugin.luck-draw.frontend.team.getActivity");
            e._postNetWork({
                url: a,
                data: {
                    activity_id: t.data.activeid
                },
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? t.setData({
                        activityInfo: e.data,
                        showInfo: !0
                    }) : wx.showToast({
                        title: e.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    onClickRight: function() {
        this.setData({
            showInfo: !1
        });
    },
    onChangeaddNum: function(t) {
        this.setData({
            addNum: t.detail
        });
    },
    onChangeTel: function(t) {
        this.setData({
            tel: t.detail
        });
    },
    joinActivity: function() {
        var t = this, a = {
            activity_id: t.data.activeid,
            total: this.data.addNum,
            address: JSON.stringify(this.data.activityInfo.address),
            pid: this.options.mid || 0
        };
        if (2 == this.data.activityInfo.type && 1 == this.data.activityInfo.need_address) {
            if ("" == this.data.tel) return void wx.showToast({
                title: "请填写手机号",
                duration: 1e3,
                icon: "none"
            });
            a.address = JSON.stringify({
                mobile: this.data.tel
            });
        } else if (0 == Object.keys(this.data.activityInfo.address).length) return void wx.showToast({
            title: "请选择收货地址",
            duration: 1e3,
            icon: "none"
        });
        if (2 != this.data.activityInfo.type_id) {
            var i = e.getNetAddresss("plugin.luck-draw.frontend.team.freeJoinActivity");
            e._postNetWork({
                url: i,
                data: a,
                success: function(a) {
                    var e = a.data;
                    wx.showToast({
                        title: e.msg,
                        duration: 1e3,
                        icon: "none"
                    }), 1 == e.result && (t.getData(), t.setData({
                        showInfo: !1
                    }));
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        } else {
            a.money = this.data.info.money, this.setData({
                showInfo: !1
            });
            var o = JSON.stringify(a);
            wx.navigateTo({
                url: "/packageH/newDraw/payment/payment?datas=" + o
            });
        }
    },
    onClickShowShare: function() {
        this.setData({
            showShare: !0
        });
    },
    onCloseShare: function() {
        this.setData({
            showShare: !1
        });
    },
    onClosePoster: function() {
        this.setData({
            showposter: !1
        });
    },
    onSelectShare: function(t) {
        "分享海报" == t.detail.name && this.getPoster(), this.onCloseShare();
    },
    getPoster: function() {
        this.setData({
            showposter: !0
        });
    },
    bindinputComment: function(t) {
        this.setData({
            comment_input: t.detail.value
        });
    },
    sendComment: function() {
        var t = this;
        if ("" != this.data.comment_input) {
            var a = e.getNetAddresss("plugin.luck-draw.frontend.index.comment");
            e._postNetWork({
                url: a,
                data: {
                    activity_id: this.data.activeid,
                    content: this.data.comment_input
                },
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? (t.setData({
                        comment_input: ""
                    }), t.getComment()) : wx.showToast({
                        title: e.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        } else wx.showToast({
            title: "不能发送空白信息",
            duration: 1e3,
            icon: "none"
        });
    },
    gotoWinnersList: function() {
        wx.navigateTo({
            url: "/packageH/newDraw/winnersList/winnersList?id=" + this.data.activeid + "&num=" + this.data.info.current_round
        });
    },
    gotoLotteryComplaint: function() {
        wx.navigateTo({
            url: "/packageH/newDraw/lotteryComplaint/lotteryComplaint?id=" + this.data.activeid
        });
    },
    getAddress: function() {
        this.setData({
            showAddress: !0
        });
    },
    confirmSelectAddress: function(a) {
        var e;
        this.setData((t(e = {}, "activityInfo.address", a.detail), t(e, "showAddress", !1), 
        e));
    },
    getGoodsDetails: function(t) {
        var a = this, i = t.currentTarget.dataset.id, o = e.getNetAddresss("goods.goods.get-goods-page");
        e._postNetWork({
            url: o,
            data: {
                id: Number(i)
            },
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var i = 1e3 * a.data.info.end_time - new Date().getTime();
                    e.data.get_goods.end_time = i > 0 ? i : 0, a.setData({
                        goodsPopupShow: !0,
                        hand_goods_obj: e.data.get_goods
                    });
                }
            }
        });
    },
    gotoLuckyDraw: function() {
        wx.navigateTo({
            url: "/packageH/newDraw/luckyDraw/luckyDraw"
        });
    },
    gotoMydraw: function() {
        wx.navigateTo({
            url: "/packageH/newDraw/mydraw/mydraw"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(t) {
        console.log(t);
        var a = wx.getStorageSync("yz_uid"), e = "";
        return a && (e = a), {
            title: this.data.info.activity_name,
            path: "/packageH/newDraw/newDrawIndex/newDrawIndex?id=" + this.data.activeid + "&mid=" + e
        };
    }
});